import random
import os
import time
import requests

def create():
    header = {
        "Content-Type": "image/jpeg",
        'UserAgent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
                                'AppleWebKit/537.36 (KHTML, like Gecko) '
                                'Chrome/90.0.4430.212 '
    }
    cwd = os.getcwd()
    base_path = os.path.join(cwd, 'codeimg')
    for i in range(10):
        print(f'{i}')
        rand = random.random()
        url = f'https://www.vin114.net/web/code/getcode3.jhtml?{rand}'
        response = requests.get(url, headers=header)
        f_path = os.path.join(base_path, f'{rand}.jpeg')
        with open(f_path, 'wb') as f:
            f.write(response.content)
        time.sleep(1)


if __name__ == "__main__":
    create()
